package com.boxin.ims.modules.wechat.busi;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boxin.ims.modules.wechat.entity.WechatMember;
import com.boxin.ims.modules.wechat.entity.dic.Address;
import com.boxin.ims.modules.wechat.entity.dic.Storefront;
import com.boxin.ims.modules.wechat.service.dic.StorefrontService;
import com.boxin.ims.modules.wechat.utils.BaiduMap;

/**
 * @author Jakemanse
 * @date 2013-12-10
 * @function <p>位置服务处理器 </p>
 */
@Service
public class LocationProcessor extends BusinessProcessor {
	
	@Autowired
	StorefrontService storefrontService;
	
	@Override
	public ProcessMessage process() {
		WechatMember member =	memberCheckAndReply();
		if(member!=null){
			Map<String,String> msgMap = getMessageMap();
			String Location_X = getLocationMessage().getLocation_X();
			String Location_Y = getLocationMessage().getLocation_Y();
			try {
				
				Address address =	BaiduMap.getAddressInfoByXY(Location_X, Location_Y);
				List<Storefront> storefrontList = 	storefrontService.findByXY(getUser().getId(), address);
				/////
				if(storefrontList != null && !storefrontList.isEmpty()){
					String reply = "店里面的地址:";
					for(Storefront sf:storefrontList){
						reply += sf.getAddress() +"\r\n";
					}
					writeToUser(reply);
				}else{
					writeToUser("未找到您所在区域的阳光麦康无糖食品用品店");
				}
				
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		
		return null;
	}

	@Override
	public boolean isNeedBeMember() {
		
		return true;
	}

}
